package cn.itcast.hotel.mq;

import cn.itcast.hotel.constants.MqConstants;
import cn.itcast.hotel.service.IHotelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;
@Slf4j
@Component
public class HotelRabbitListener {
    @Autowired
    IHotelService service;

    @RabbitListener(queues = MqConstants.HOTEL_INSERT_QUEUE)
    public void indexListener(Long id){
        try {
            service.indexHotel(id);
        } catch (IOException e) {
            e.printStackTrace();
            log.error("全量修改发生异常，异常信息为{}",e.getMessage());
        }
    }

    @RabbitListener(queues = MqConstants.HOTEL_DELETE_QUEUE)
    public void deleteListener(Long id){
        try {
            service.deleteHotel(id);
        } catch (IOException e) {
            e.printStackTrace();
            log.error("删除发生异常，异常信息为{}",e.getMessage());
        }
    }
}
